package mytf.core.toolbox;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
	public static String getMd5(byte[] source){
		String s = null;
		char hexDigits[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("MD5");
			md.update(source);
			byte temp[] = md.digest();
			char str[] = new char[16 * 2];
			int k = 0;
			for(int i = 0;i < 16;i++){
				byte byte0 = temp[i];
				str[k++] = hexDigits[byte0 >>> 4 & 0xf];
				str[k++] = hexDigits[byte0 & 0xf];
			}
			s = new String(str);
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return s;
	}
	
	
	public static void main(String[] args) {
		String a = "ABC";
		byte[] source = a.getBytes();
		a = MD5.getMd5(source);
		System.out.println(a.length());
	}
	
}
